package com.hisan.freeride.home.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hisan.freeride.R;
import com.lzy.ninegrid.ImageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 公益广场图片适配器
 * Created by Administrator on 2017/1/3.
 */

public class GreensAdapter extends BaseAdapter {
    private Activity context;
    private List<String>person;
    private boolean ismore=true;

    public GreensAdapter(Activity context, List<String> lifeList) {
        this.context = context;
        this.person=lifeList;
    }

    @Override
    public int getCount() {
        return person.size();
    }

    public void setBoolean(boolean ismore) {
        this.ismore=ismore;
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        HotGridViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.creens_item, null);
            holder = new HotGridViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (HotGridViewHolder) convertView.getTag();
        }
        List<ImageInfo> imageInfo=new ArrayList<>();
        for (String  iamge : person) {
            ImageInfo info = new ImageInfo();
            info.setThumbnailUrl(iamge);
            info.setBigImageUrl(iamge);
            imageInfo.add(info);
        }
        Glide.with(context).load(person.get(position))//
                .placeholder(R.drawable.ic_default_color)//
                .error(R.drawable.ic_default_color)//
                .diskCacheStrategy(DiskCacheStrategy.ALL)//
                .into(holder.getImageView());

        return convertView;
    }

    private class HotGridViewHolder {
        private ImageView imageview;
        private View view;

        private HotGridViewHolder(View view) {
            this.view = view;
        }

        ImageView getImageView() {
            if (imageview == null) {
                imageview = (ImageView) view.findViewById(R.id.guotu);
            }
            return imageview;
        }

    }
}
